<template>
  <el-row style="width: 80%">
    <!-- 作业表格 -->
    <el-table
      :data="homeworkTable"
      style="margin-left: 30px; margin-top: 20px; width: 95%"
    >
      <!-- 展开详情 -->
      <el-table-column type="expand" fixed="left">
        <template slot-scope="props">
          <el-form label-position="left">
            <el-form-item label="作业描述：">
              <span>{{ props.row.assignmentDescription }}</span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <!-- 作业名 -->
      <el-table-column
        label="作业名"
        width="180"
        sortable
        prop="assignmentName"
      >
        <template slot-scope="scope">
          <b>{{ scope.row.assignmentName }}</b>
        </template>
      </el-table-column>
      <!-- 作业课程 -->
      <el-table-column
        label="所属课程"
        width="180"
        sortable
        prop="course.course_name"
      >
      </el-table-column>
      <!-- 作业期限 -->
      <el-table-column label="作业期限" width="250">
        <template slot-scope="scope">
          <el-row>
            <el-tag size="mini" type="success">起</el-tag>
            {{ $global.formatTimeString(scope.row.startTime) }}
          </el-row>
          <el-row>
            <el-tag size="mini" type="danger">止</el-tag>
            {{ $global.formatTimeString(scope.row.endTime) }}
          </el-row>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleUpHW(scope.$index, scope.row)"
            >作业详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </el-row>
</template>

<script>
import stuInfo from "../../store/student";
import axios from "axios";
import qs from "qs";

export default {
  computed: {
    courseList() {
      return stuInfo.getters.getCourseList;
    },
  },
  data() {
    return {
      homeworkTable: [],
    };
  },
  mounted() {
    // 遍历课程获取作业信息
    // console.log("总列表", this.courseList);
    this.courseList.forEach((course) => {
      let id = course.courseId;
      // console.log(id);
      axios
        .post("/api/showAllAssignmentTopics", qs.stringify({ courseId: id }))
        .then((res) => {
          // console.log("作业", res);
          res.data.assignmentTopicList.forEach((hw) => {
            hw.course = course;

            this.homeworkTable.push(hw);
          });
          // console.log("列表变量", this.homeworkTable);
        })
        .catch((err) => {
          console.log("作业", err);
        });
    });
  },
  methods: {
    handleUpHW(index, row) {
      // console.log(index, row);
      stuInfo.commit("setHwDetail", row);
      stuInfo.commit("setChoosenCourse", row.course);
      // console.log(this.hwDetail);
      this.$router.push("/CourseDetail/HWDetail");
    },
  },
};
</script>

<style>
</style>